/*
 * @Description: 目录树相关接口
 * @Author: Rfan
 * @Date: 2022-06-30 18:39:47
 * @LastEditTime: 2022-07-01 14:06:00
 */

import { Key } from 'react';
import request from '@/utils/request';
import { IFolderTreeNode } from '@/interfaces/folderTree';

// 新增数据类型节点参数
export interface ITreeNodeDataParams {
  condition: string;
  nodeId: number;
  nodeName: string;
  remark?: string;
}

// 新增描述类型节点参数
export interface ITreeNodeDescParams {
  nodeId: number;
  nodeName: string;
  remark?: string;
}

// 新增分组类型节点参数
export interface ITreeNodeGroupParams {
  dirTreeRuleId: number;
  nodeId: number;
  remark?: string;
}

export interface IDictList {
  code: string;
  deleted: number;
  id: number;
  isValid: number;
  name: string;
  remark: string;
  typeId: number;
  value: string;
}

export interface IRuleConfig {
  dictList?: IDictList[];
  manualValueRule?: any[];
  ruleType: number;
  valueRangeRule?: any[];
}

export interface IRule {
  configRule: boolean;
  // eslint-disable-next-line camelcase
  field_name: string;
  level: number;
  ruleConfig: IRuleConfig;
}

// 分组方案参数
export interface IGroupPlanParams {
  nodeId: number;
  remark: string;
  rule: IRule;
  ruleName: string;
}

export interface IFetchGroupPlanParams {
  archiveTypeId?: number;
  createTime?: string;
  id?: number;
  operator?: number;
  operatorName?: string;
  operatorTime?: string;
  remark?: string;
  ruleName?: string;
}

// 编辑树节点
export interface IEditTreeNodeParams {
  id?: number;
  nodeCode?: string;
  nodeConditionJson?: string;
  nodeLevel?: number;
  nodeName?: string;
  nodeType?: number;
  pid?: number;
  remark?: string;
  sortNo?: number;
}

// 初始化目录树
export function initFolderTree() {
  return request({
    url: `/archive-directory-tree/init`,
    method: 'get'
  });
}

// 查询根节点
export function fetchRootTreeNode() {
  return request({
    url: `/archive-directory-tree/root-node`,
    method: 'get'
  });
}

// 查询根节点
export function fetchFondNodeByUnitId(unitId: Key) {
  return request({
    url: `/archive-directory-tree/fonds-node/${unitId}`,
    method: 'get'
  });
}

// 查询子节点
export function fetchChildTreeNode(id: number | string) {
  return request({
    url: `/archive-directory-tree/child-node/${id}`,
    method: 'get'
  });
}

// 增加普通目录树节点
export function addTreeNode(data: Partial<IFolderTreeNode>) {
  return request({
    url: `/archive-directory-tree/`,
    method: 'post',
    data
  });
}

// 增加目录树数据节点
export function addTreeNodeData(data: Partial<ITreeNodeDataParams>) {
  return request({
    url: `/archive-directory-tree/data-node`,
    method: 'post',
    data
  });
}

// 增加目录树描述节点
export function addTreeNodeDesc(data: ITreeNodeDescParams) {
  return request({
    url: `/archive-directory-tree/desc-node`,
    method: 'post',
    data
  });
}

// 增加目录树分组节点
export function addTreeNodeGroup(data: ITreeNodeGroupParams) {
  return request({
    url: `/archive-directory-tree/group-node`,
    method: 'post',
    data
  });
}

// 通过ID删除目录树节点
export function deleteFolderTreeNodeById(id: Key) {
  return request({
    url: `/archive-directory-tree/${id}`,
    method: 'delete'
  });
}

// 增加目录树分组方案
export function addGroupPlan(data: IGroupPlanParams) {
  return request({
    url: `/archive-directory-tree-rule/`,
    method: 'post',
    data
  });
}

// 增加目录树分组方案
export function fetchGroupPlanList(data: IFetchGroupPlanParams) {
  return request({
    url: `/archive-directory-tree-rule/list`,
    method: 'post',
    data
  });
}

// 编辑目录树节点
export function editTreeNode(data: IEditTreeNodeParams) {
  return request({
    url: `/archive-directory-tree/`,
    method: 'put',
    data
  });
}
